package lib

import (
	"strings"
)

func init() {
	Probs = append(Probs, Problem{
		Num:         6,
		Discription: "Z形变换",
		Level:       2,
		Labels: map[string]int{
			"字符串": 1,
			"数学":  1,
		},
	})
}

func Convert(s string, numRows int) string {
	if numRows == 1 {
		return s
	}

	cols := make([][]byte, numRows)
	//每一组有2*numRows - 2个字符
	div := 2*numRows - 2
	for i := range s {
		ch := s[i]
		mod := i % div
		//确定行号
		col := min(mod, div-mod)
		cols[col] = append(cols[col], ch)
	}

	//一行接一行的拼接
	var builder strings.Builder
	for i := range cols {
		builder.WriteString(string(cols[i]))
	}

	return builder.String()
}
